package org.cuit.epoch.seon.example;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Seon
 * @version 1.0
 * @since 2024-09-18
 */
public class Composite extends Component {

    public Composite(String name) {
        super(name);
    }

    public List<Component> children = new ArrayList<>();

    @Override
    public void add(Component component) {
        children.add(component);
    }

    @Override
    public void remove(Component component) {
        children.remove(component);
    }

    @Override
    public void display(int depth) {
        for (int i = 0; i < depth; i++) {
            System.out.print("--");
        }
        System.out.println(name);
        for (Component child : children) {
            child.display(depth + 1);
        }
    }
}
